//
//  ZSYViewController.m
//  testpbl
//
//  Created by 黄权浩 on 15/8/3.
//  Copyright (c) 2015年 黄权浩. All rights reserved.
//

/*
 
 实现思想
 1.约束要给contentView压力
 2._tab.rowHeight = UITableViewAutomaticDimension;
 3._tab.estimatedRowHeight = 140.0;给一个近似的平均高度
 4.tableView:estimatedHeightForRowAtIndexPath: 实现这个方法给出更精确的高度
 
 */



#import "ZSYViewController.h"

@interface ZSYViewController ()
{
    @private
    NSArray *dataarr;
    UIImageView *scrRightShow;
}
@end

@implementation ZSYViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    scrRightShow = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 10, 44)];
    scrRightShow.backgroundColor = [UIColor redColor];
    scrRightShow.layer.cornerRadius = 4.0;
    scrRightShow.layer.masksToBounds = YES;
    [_rightShow addSubview:scrRightShow];
    dataarr = @[@"In a storyboard-based application, you will often want to do a little preparation before navigation", @"In a storyboard-based application, you will often want to do a little preparation before navigationIn a storyboard-based application, you will often want to do a little preparation before navigation", @"In a storyboard-based application, you will often want to do a little preparation before navigation", @"In a storyboard-based application, you will often want to do a little preparation before navigationIn a storyboard-based application, you will often want to do a little preparation before navigationIn a storyboard-based application, you will often want to do a little preparation before navigation", @"In a storyboard-based application, you will often want to do a little preparation before navigationIn a storyboard-based application, you will often want to do a little preparation before navigation", @"In a storyboard-based application, you will often want to do a little preparation before navigation", @"In a storyboard-based application, you will often want to do a little preparation before navigationIn a storyboard-based application, you will often want to do a little preparation before navigation", @"In a storyboard-based application, you will often want to do a little preparation before navigation", @"In a storyboard-based application, you will often want to do a little preparation before navigationIn a storyboard-based application, you will often want to do a little preparation before navigationIn a storyboard-based application, you will often want to do a little preparation before navigation", @"In a storyboard-based application, you will often want to do a little preparation before navigationIn a storyboard-based application, you will often want to do a little preparation before navigationIn a storyboard-based application, you will often want to do a little preparation before navigationIn a storyboard-based application, you will often want to do a little preparation before navigationIn a storyboard-based application, you will often want to do a little preparation before navigationIn a storyboard-based application, you will often want to do a little preparation before navigationIn a storyboard-based application, you will often want to do a little preparation before navigationIn a storyboard-based application, you will often want to do a little preparation before navigationIn a storyboard-based application, you will often want to do a little preparation before navigationIn a storyboard-based application, you will often want to do a little preparation before navigation"];
    
    _tab.rowHeight = UITableViewAutomaticDimension;
    _tab.estimatedRowHeight = 44.0;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return dataarr.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *cellId = @"dawfads";
    ZSYCell *cell = [tableView dequeueReusableCellWithIdentifier:cellId];
    if (!cell) {
        NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"ZSYCell" owner:self options:nil];
        cell = nib[0];
    }
    cell.descriptionLabel.text = dataarr[indexPath.row];
    return cell;
}

//scrollView delegate
- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
    float answerTableVHeight = 0;
    for (int i = 0; i < dataarr.count; i++) {
        CGRect rect = [_tab rectForRowAtIndexPath:[NSIndexPath indexPathForRow:i inSection:0]];
        answerTableVHeight = answerTableVHeight + rect.size.height;
    }
    if (scrollView == _tab) {
        NSLog(@"scrollview.c.y = %f  tabhight%f", scrollView.contentOffset.y, _tab.contentOffset.y);
        [UIView animateWithDuration:0.1 animations:^{
            scrRightShow.frame = CGRectMake(0, scrollView.contentOffset.y+64, 10, 44);
            if (scrRightShow.bounds.origin.y > answerTableVHeight) {
                scrRightShow.frame = CGRectMake(0, answerTableVHeight-44, 10, 44);
            }
        }];
    }
    
  
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
